/**
 * Widget基类
 * @author    yanggy
 * @version    0.1
 */

define(["dojo/_base/declare",
    "dojo/_base/array",
    "dojo/_base/fx" ,
    "dojo/_base/lang",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/window",
 
    "../util/utils"],
    function (declare, array, baseFx, lang, _WidgetBase, _TemplatedMixin, win,  utils) {

        return declare([_WidgetBase, _TemplatedMixin], {

            constructor:function (args) {
                this.handlers = [];	// 注册主题列表
                this.connects = [];	// 监听事件列表

                //this.geoDataManager = GeoDataManager.getInstance();
                
                this.utils = utils;
            },

            postMixInProperties:function () {
                this.inherited(arguments);
            },

            postCreate:function () {
                this.inherited(arguments);
            },

            startup:function () {
                this.inherited(arguments);
            },

            destroy:function () {
                this.cleanup();
                this.inherited(arguments);
            },

            /**
             * 取消登记主题和注册事件
             */
            cleanup:function () {
                this.clearSubscribes();
                this.clearConnects();
            },

            /**
             * 取消登记主题
             */
            clearSubscribes:function () {
                array.forEach(this.handlers, function (h) {
                    h.remove();
                });
                this.handlers = [];
            },

            /**
             * 取消注册事件
             */
            clearConnects:function () {
                array.forEach(this.connects, function (c) {
                    c.remove();
                });
                this.connects = [];
            },

            /**
             * 执行淡入动画
             * @param duration
             * @param callback
             */
            fadeIn:function (duration, callback) {
                if (!this.domNode) {
                    return;
                }
                baseFx.fadeIn({
                    node:this.domNode,
                    duration:duration,
                    onEnd:lang.hitch(this, function () {
                        if (typeof callback === "function") {
                            callback();
                        }
                    })
                }).play();
            },

            /**
             * 执行淡出动画
             * @param duration
             * @param callback
             */
            fadeOut:function (duration, callback) {
                if (!this.domNode) {
                    return;
                }
                baseFx.fadeOut({
                    node:this.domNode,
                    duration:duration,
                    onEnd:lang.hitch(this, function () {
                        this.destroy();

                        if (typeof callback === "function") {
                            callback();
                        }
                    })
                }).play();
            },
            /**
             * 获取界面内容框大小
             */
            getContentSize:function () {
                var box = win.getBox();
                return { w:box.w, h:box.h };
            }
        });
    });